﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CatUtils.Utils.SpecialUtils.View
{
    /// <summary>
    /// 有三种状态的用户选择功能 返回Yes No Cancel
    /// </summary>
    public partial class UserDialog : Form
    {
        /// <summary>
        /// 通过这个设定关闭的时间
        /// </summary>
        int LocalCloseTime = 0;
        /// <summary>
        /// 窗口标题
        /// </summary>
        string WindowsTitle = "";
        /// <summary>
        /// 有三种状态的用户选择功能 返回Yes No Cancel
        /// </summary>
        /// <param name="Tip">提示框里的内容</param>
        /// <param name="YesTip">Yes按钮文字，不超过中文5字，否则显示不全</param>
        /// <param name="NoTip">No按钮文字，不超过中文5字，否则显示不全</param>
        /// <param name="CancleTip">Cancle按钮文字，不超过中文5字，否则显示不全</param>
        /// <param name="AppTip">主界面，最顶部半透明位置的提示框。</param>
        public UserDialog(string Tip, string YesTip, string NoTip, string CancleTip, string AppTip = "")
        {
            InitWinform(Tip, YesTip, NoTip, CancleTip, AppTip);
        }
        /// <summary>
        /// 有三种状态的用户选择功能 返回Yes No Cancel  并且设置关闭时间
        /// </summary>
        /// <param name="Tip">提示框里的内容</param>
        /// <param name="YesTip">Yes按钮文字，不超过中文5字，否则显示不全</param>
        /// <param name="NoTip">No按钮文字，不超过中文5字，否则显示不全</param>
        /// <param name="CancleTip">Cancle按钮文字，不超过中文5字，否则显示不全</param>
        /// <param name="CloseSecond"></param>
        /// <param name="AppTip">主界面，最顶部半透明位置的提示框。</param>
        public UserDialog(string Tip, string YesTip, string NoTip, string CancleTip, int CloseSecond, DialogResult CloseResult, string AppTip = "")
        {
            this.DialogResult = CloseResult;
            InitWinform(Tip, YesTip, NoTip, CancleTip, AppTip);
            LocalCloseTime = CloseSecond;
            TimerClose.Enabled = true;
            TimerClose.Interval = 1000;
        }
        /// <summary>
        /// 初始化窗口
        /// </summary>
        /// <param name="Tip"></param>
        /// <param name="YesTip"></param>
        /// <param name="NoTip"></param>
        /// <param name="CancleTip"></param>
        /// <param name="AppTip"></param>
        private void InitWinform(string Tip, string YesTip, string NoTip, string CancleTip, string AppTip)
        {
            this.Text = AppTip;
            InitializeComponent();
            label1.Text = Tip;
            button1.Text = YesTip;
            button2.Text = NoTip;
            button3.Text = CancleTip;
            WindowsTitle = AppTip;
        }

        private void Button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.No;
            Close();
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Yes;
            Close();
        }

        private void Button3_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            Close();
        }

        private void TimerClose_Tick(object sender, EventArgs e)
        {
            this.Text = $"{WindowsTitle} 将于{LocalCloseTime--}秒后自动关闭。";
            if (LocalCloseTime <= 0)
            {
                Close();
            }
        }
    }
}